// 跨层级组件通信
import { createContext, useContext } from 'react'

const MsgContext = createContext()
const A = () =>{
  return (
    <div>
      我是组件A
      <B/>
    </div>
  )
}
const B = () =>{
  const msg = useContext(MsgContext)
  return (
    <div>
      我是组件B: {msg}
    </div>)
}
function App() {
  const msg = '我只是一个消息'
  return (
    <div className="App">
      <MsgContext.Provider value={msg}>
        <A/>
      </MsgContext.Provider>
    </div>
  )
}

export default App;


















